const { error } = require('./utils/output')
const { loginUrl, idUrl, submitUrl, pageUrl, warrantUrl } = require('./utils/url')

const login = require('./src/login')
const getUserId = require('./src/getUserId')
const createServer = require('./src/createServer')
const checkUserinfo = require('./src/userinfoUnit')
const submitRequest = require('./src/submitRequest')
const getPageResult = require('./src/getPageResult')

!(async () => {
  try {
    const [willSubmit, userinfo] = await checkUserinfo()
    await login(loginUrl, userinfo)
    const id = await getUserId(idUrl)
    willSubmit && await submitRequest(submitUrl, id, userinfo)
    await getPageResult(pageUrl, warrantUrl, id)
    await createServer()
  } catch (e) {
    error('操作失败，错误信息：', e)
  }
}
)()